package proto_wearebatman;

public class Switch implements IhasOutput {

    private Output output;
    private Wire wire;
    private int state;
    private String name;

    public Switch(String name) {
        this.name = name;
        this.output = new Output();
        this.state = 0;

        // Proto Output
        Main.println("Switch created: " + this.name);
    }

    public void operate() {
        this.output.setData(this.state);

        //Main.println(this.name + ".operate() | Data = " + this.output.getData());

        this.wire.operate();
    }

    public int getOutputData(int pin) {
        return this.output.getData();
    }

    public void setOutputData(int pin, int data) {
        this.output.setData(data);
    }

    public void connectWireOutput(int pin, Wire wire) {
        this.wire = wire;
    }

    public void setState(int data) {
        this.state = data;
        Main.println(this.name + " has been " + (data == 1 ? "" : "de") + "activated.");
    }

    public void setStateSilent(int data) {
        this.state = data;
    }

    public String getName() {
        return this.name;
    }

    public void resetCounter() {
    }

    public String getFinalState() {
        return Integer.toString(this.getOutputData(0)) + " (" + Integer.toString(this.state) + ")";
    }
}
